package cn.edu.scau.cmi.wujiaxian.exercise11;

import java.awt.FlowLayout;
import java.io.File;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import cn.edu.scau.cmi.wujiaxian.exercise10.FileAccept;

public class WindowItemEvent extends JFrame{
	private static final long serialVersionUID = 4174621914605686809L;

	JComboBox<String> choice;
	JTextArea textArea;
	PoliceListen2 listener;
	
	public WindowItemEvent() {
		init();
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	void init() {
		setLayout(new FlowLayout());
		choice = new JComboBox<>();
		choice.addItem("请选择文件：");
		File dir = new File("C:\\Users\\lenovo\\git\\201734020124_wu_jiaxian\\201734020124吴嘉贤\\src\\cn\\edu\\scau\\cmi\\wujiaxian\\exercise11");
		FileAccept fileAccept = new FileAccept(); //过滤器
		fileAccept.setExtendName("java");
		String[] fileName = dir.list(fileAccept); //获取全部文件名
		for (String name : fileName) {
			choice.addItem(name);
		}
		textArea = new JTextArea(9, 30);
		listener = new PoliceListen2();
		listener.setJComboBox(choice);
		listener.setJTextArea(textArea);
		choice.addItemListener(listener); //增加监听器
		add(choice);
		add(new JScrollPane(textArea));
	}
	
}
